$(function ()
{
    //设置指定面板展开
    $('#layout').layout('expand', 'north');
    var datagrid = $("#dg").datagrid(
        {
            url : "../../api/dd_findAllOrder?checkState=5",
            //isField : "testnum",
            method : "get",
            width : 1000,
            height : 550,
            rownumbers : true, //显示行号
            singleSelect : true,//只支持单选
            toolbar : '#tc',//设置工具栏的id
            pagination : true, //显示分页
            pageSize : 10, //分页大小
            pageList : [5, 10, 15, 20], //每页的个数
            beforePageText : '第',
            afterPageText : '页    共 {pages} 页',
            displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录',
            fit : true, //自动补全
            fitColumns : true,
            title : "",
            columns : [[//每个列具体内容
                    {
                        field : 'ck',
                        checkbox : true
                    },
                     {
                        field : 'orderNo',
                        title : '订单编码',
                        width : 100,
                        align : 'center'
                       
                    },
                    {
                        field : 'productLine',
                        title : '线体名称',
                        width : 150,
                        align : 'center'
                        
                    },
                    {
                        field : 'productLineNo',
                        title : '线体编码',
                        width : 100,
                        align : 'center'
                    },
                    {
                        field : 'productDescription',
                        title : '型号描述',
                        width : 100,
                        align : 'center'
                    },
                    {
                        field : 'planCount',
                        title : '计划数量',
                        width : 100,
                        align : 'center'
                    },
                     {
                        field : 'checkCount',
                        title : '应抽数量',
                        width : 100,
                        align : 'center'
                    },
                    {
                        field : 'checkDate',
                        title : '计划时间',
                        width : 100,
                        align : 'center',
                        formatter:function(val,row){
                            var now = new Date(val);
                            return now.format("yyyy-MM-dd hh:mm:ss");
                        }
                    },
                    {
                        field : 'checkState',
                        title : '抽样检测状态',
                        width : 130,
                        align : 'center',
                        formatter:function(value , record , index)
                        {
                            if(value==0){
                                return '<span style=color:red; >待检测</span>' ;
                            }else if( value ==1){
                                return '<span style=color:green; >检测中</span>' ; 
                            }else if( value ==2){
                                return '<span style=color:green; >整改中</span>' ; 
                            }else if( value ==3){
                                return '<span style=color:green; >检测完成</span>' ; 
                            }else if( value ==4){
                                return '<span style=color:green; >报告待审核</span>' ; 
                            }else if(value ==5){
                                return '<span style=color:green; >报告待审批</span>' ; 
                            }
                            else{
                                return '<span style=color:green; >订单结束</span>' ; 
                            }
                        }
                    },
                ]],
            onLoadSuccess : function (data)
            {
                $("a[name='opera2']").linkbutton(
                {
                    text : '>>>',
                    plain : true,
                    iconCls : 'icon-search'
                }
                );
            },
        }
        );
    //查看报告
    $("#viewReport").click(function ()
    {
        window.open("../../menu_nj/ReportManage/ReportPreview");
    }
    );

    //查看订单
    $("#viewOrder").click(function ()
    {

        var rows = datagrid.datagrid('getSelections');

        if (rows.length <= 0)
        {
            $.messager.alert('警告', '您没有选择', 'error');
        }
        else if (rows.length > 1)
        {
            $.messager.alert('警告', '不支持批量接收', 'error');
        }
        else
        {
            var index = datagrid1.datagrid('getRowIndex', datagrid1.datagrid('getSelected'));
            var row1 = datagrid1.datagrid('getData').rows[index];
            window.open("../../menu/OrderManage/btn_ViewOrderOfReportRelease?testnum=" + row1.testnum);
            // window.location.href="../../menu/OrderManage/btn_ViewOrderOfReportRelease?testnum="+row1.testnum;
        }

    }
    );

    //审批
    $("#approveOrder").click(function ()
    {

       //获取选中的行
        var rows = datagrid.datagrid('getSelections');
        if (rows.length <= 0)
        {
            $.messager.alert({
                        title:'警告',
                        msg:'您没有选择',
                        icon: 'error',
                        width: 200,
                        top:200
                    });
        }
        else
        {
            const orderNo=rows[0].orderNo;//订单编码
            window.location.href="../../menu_nj/ReportManage/ReportApprove_Detail?orderNo="+orderNo;
        }

    }
    );
}
);


//整体模糊查询
function searchTemporarySam()
{

    var samplename = $('#samplename').combobox('getText');
    var sampletype = $('#sampletype').searchbox('getValue');
    var producttype = $('#producttype').combobox('getText');
    // var bailor = $('#bailor').textbox('getValue');
    var bailor = "";
    var samplegrade = $('#samplegrade').combobox('getText');
    var purpose = $('#purpose').combobox('getText');
    var orderno = $('#orderno').textbox('getValue');
    var starttime = $('#starttime').datetimebox('getValue');
    var endtime = $('#endtime').datetimebox('getValue');

    //$.messager.alert('操作提示','名称'+sampleName+'类型'+productType+'型号'+modelNumber+'等级'+sampleLevel);

    //reload形式加载模糊查询,成功
    $('#dg').datagrid('reload', '../../api/searchAllOrderInfoBySomeKe');

    var pagetitle = "报告审核";
    var page = "menu/OrderManage/ReportCheck";
    var operation = "2";
    var detail = "报告查询";
    $.ajax(
    {
        url : '../../api/insertSystemLog',
        method : 'get',
        dataType : 'json',
        data :
        {
            pagetitle : pagetitle,
            page : page,
            operation : operation,
            userrealname : realname,
            userno : userno,
            detail : detail
        },
        success : function (r)
        {
            if (r == 1)
            {
                datagrid1.datagrid('acceptChanges');
                $.messager.show(
                {
                    msg : r.msg,
                    title : '成功'
                }
                );

                datagrid1.datagrid('reload');
            }
            else
            {

                $.messager.alert('错误', r.msg, 'error');
            }
            datagrid1.datagrid('unselectAll');
        }
    }
    );

}

